package com.bawei.websocketdemo

import android.app.Application
import android.util.Log
import android.widget.Toast
import com.bawei.websocketdemo.test.YaoSocketUtils
import org.java_websocket.handshake.ServerHandshake
import java.lang.Exception

/**
 * @Author : yaotianxue
 * @Time : On 2023/6/25 15:56
 * @Description : App
 */
class App:Application(){
   companion object{
        lateinit var websocket:SocketUtils
   }

    override fun onCreate() {
        super.onCreate()
        initSocket()
    }
    private fun initSocket() {
        websocket = SocketUtils.Builder()
            .setWebsocket_url("124.70.98.255:8083/api/websocket/100")
            .setListener(object :SocketUtils.ReceiveMsgListener{
                override fun onReceive(message: String?) {
                    Toast.makeText(this@App,message,Toast.LENGTH_SHORT).show()
                }

                override fun onOpen(handshakedata: ServerHandshake?) {

                }

                override fun onError(ex: Exception?) {

                }

                override fun onClose(code: Int, reason: String?, remote: Boolean) {

                }
            })
            .build()
    }



}